#cmake_minimum_required (VERSION 2.6)
cmake_minimum_required(VERSION 3.14.1)
SET(GPU_PERF_MAJOR_VERSION 3)
SET(GPU_PERF_MIN_VERSION 5)
SET(GPU_PERF_PATCH_VERSION 10)
SET(GPU_PERF_VERSION 153)

set(${PROJECT_NAME} GPU-perf)
project (GPU-perf )
#LANGUAGES CXX)
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/../lib )
EXECUTE_PROCESS( COMMAND uname -m
                 COMMAND tr -d '/r/n'
                 OUTPUT_VARIABLE ARCHITECTURE )
message( -- " " STATUS " Architecture: " ${ARCHITECTURE} )
if ( ${ARCHITECTURE} MATCHES "X86|x86" )
    message( -- " " STATUS " Machine is X86 Architecture" )
else()
    LINK_DIRECTORIES( /usr/local/lib )
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../build)

# Second, for multi-config builds (e.g. msvc)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
    string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
    set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/../bin )
    set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/../lib )
    set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/../lib )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -pg")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

find_package(GLFW REQUIRED)
find_package(Freetype REQUIRED)
find_package(assimp REQUIRED)

set(RUN_DIR ${PROJECT_SOURCE_DIR}/../bin)

set(EXAMPLES
  shader
  fill
  pixel
  depth
  fog
  instance
  material
  sprite
  skybox
  terrain
  mesh
  msaa
  fire
  textures
  lights
  skybox
  shadowmap
  feedback
  computeshader
  waterwave
)

include_directories(../include)
include_directories(${FREETYPE_INCLUDE_DIR_freetype2})
include_directories(/usr/include/freetype2)

add_definitions(-DGLSL_PATH="${PROJECT_SOURCE_DIR}/../media/")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LINUX -std=c++11")

if($ENV{USE_GLES} MATCHES 1)
add_definitions(-DUSE_GLES=1)
add_library(glad glad/gles2.c)
else()
add_library(glad glad/gl.c)
endif()
add_library(ftgl
    ftgl/distance-field.c
    ftgl/edtaa3func.c
    ftgl/ftgl-utils.c
    ftgl/platform.c
    ftgl/texture-atlas.c
    ftgl/texture-font.c
    ftgl/utf8-utils.c
    ftgl/vector.c
    ftgl/vertex-attribute.c
    ftgl/vertex-buffer.c)

add_library(glpbcommon
    glpbcommon/node.cpp
    glpbcommon/stb_image.cpp
    glpbcommon/window.cpp
    glpbcommon/log.cpp
    glpbcommon/texture.cpp
    glpbcommon/model.cpp
    glpbcommon/meshgrid.cpp
    glpbcommon/glslprogram.cpp
    glpbcommon/textrender.cpp
    glpbcommon/perfglversion.cpp
)

target_link_libraries(glpbcommon "ftgl")

foreach(EXAMPLE ${EXAMPLES})
	file(GLOB APP_SRC ${CMAKE_SOURCE_DIR}/../src/${EXAMPLE}/*.cpp)
	set(EXAMPLE_SRC ${EXAMPLE_SRC} ${APP_SRC})
endforeach(EXAMPLE)

add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/../src/main.cpp ${EXAMPLE_SRC})

target_link_libraries(${PROJECT_NAME} glpbcommon ftgl pthread freetype assimp glad glfw GL m rt dl)

ADD_CUSTOM_TARGET(debug ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR})
ADD_CUSTOM_TARGET(release ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Release ${PROJECT_SOURCE_DIR})

set(INSTALL_DIR ${CMAKE_SOURCE_DIR}/../bin/)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${INSTALL_DIR})
